package com.asia5b.a5mall.order.adapter

import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import androidx.core.content.ContextCompat
import android.widget.TextView
import com.asia5b.a5mall.middleware.model.bean.MenuBean
import com.asia5b.a5mall.middleware.utils.showMessage
import com.asia5b.a5mall.order.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/1/13.
 */
class AftersaleDetailAdapter(list: ArrayList<MenuBean>) :
        BaseQuickAdapter<MenuBean, BaseViewHolder>(R.layout.item_aftersaledetail_adapter, list) {
    override fun convert(helper: BaseViewHolder, item: MenuBean) {
        helper.setText(R.id.tv_aftersaledetail_name, item.name)
        helper.setText(R.id.tv_aftersaledetail_value, item.value)
        val tv_aftersaledetail_value = helper.getView<TextView>(R.id.tv_aftersaledetail_value)
        val tv_aftersaledetail_copy = helper.getView<TextView>(R.id.tv_aftersaledetail_copy)

        tv_aftersaledetail_copy.setOnClickListener {
            val cm = (context as Activity).getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            val clip = ClipData.newPlainText("Asia5B", item.value)
            cm.setPrimaryClip(clip)
            showMessage(R.string.复制成功)
        }
        helper.setGone(R.id.tv_aftersaledetail_copy,item.type!=1)

        if (item.type ==8) {//价格显示红色
            tv_aftersaledetail_value.setTextColor(ContextCompat.getColor(context, R.color.color_red))
        } else {
            tv_aftersaledetail_value.setTextColor(ContextCompat.getColor(context, R.color.common_text_black))
        }
    }
}